//
//  FrontViewController.m
//  SliderPro
//
//  Created by sendInfo on 2014-04-03.
//  Copyright (c) 2014年 sendInfo. All rights reserved.
//

#import "FrontViewController.h"



@interface FrontViewController (){
    
    
    UIView *_bgVeiw;
    UILabel *_titleLab;


}


@end

@implementation FrontViewController

- (void)oneClick:(UIButton*)sender{


}
#pragma mark -

- (void)needShadow{
    
    _bgVeiw = [[UIView alloc] initWithFrame:self.navigationController.view.frame];
    _bgVeiw.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:@selector(revealToggle:)];
    tap.numberOfTapsRequired = 1;
    tap.numberOfTouchesRequired = 1;
    [_bgVeiw addGestureRecognizer:tap];

    UIPanGestureRecognizer *viewPan = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:@selector(revealToggle:)];
    [_bgVeiw addGestureRecognizer:viewPan];
    _bgVeiw.backgroundColor = [UIColor colorWithRed:0.f/255 green:0.f/255 blue:0.f/255 alpha:0.1];
    [self.navigationController.view addSubview:_bgVeiw];
}

- (void)notNeedShadow{
    
    [_bgVeiw removeFromSuperview];

}


- (void)rightClick:(UIButton*)sender{
    
    
//    loginViewController *lvc = [[loginViewController alloc] init];
//    [self.navigationController pushViewController:lvc animated:YES];

}

- (void)dealloc{

    [[NSNotificationCenter defaultCenter] removeObserver:self name:KNotificationNeedShadow object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:KNotificationNOTNeedShadow object:nil];
    
}

ON_CREATE_VIEWS(signal)
{

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needShadow) name:KNotificationNeedShadow object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notNeedShadow) name:KNotificationNOTNeedShadow object:nil];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIPanGestureRecognizer *viewPan = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:@selector(revealGesture:)];
    self.view.userInteractionEnabled = YES;
    [self.view addGestureRecognizer:viewPan];

}

ON_DELETE_VIEWS(signal)
{

}
ON_DID_APPEAR(signal)
{

}
ON_DID_DISAPPEAR(signal)
{

}
ON_WILL_APPEAR(signal)
{
    //self.title = NSLocalizedString(@"Front View", @"FrontView");
    if ([self.navigationController.parentViewController respondsToSelector:@selector(revealGesture:)] && [self.navigationController.parentViewController respondsToSelector:@selector(revealToggle:)])
    {
        // Check if a UIPanGestureRecognizer already sits atop our NavigationBar.
        if (![[self.navigationController.navigationBar gestureRecognizers] containsObject:self.navigationBarPanGestureRecognizer])
        {
            // If not, allocate one and add it.
            UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:@selector(revealGesture:)];
            self.navigationBarPanGestureRecognizer = panGestureRecognizer;
            
            [self.navigationController.navigationBar addGestureRecognizer:self.navigationBarPanGestureRecognizer];
        }
        
        // Check if we have a revealButton already.
        if (![self.navigationItem leftBarButtonItem])
        {

            UIButton *bv = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 22, 20)];
            bv.backgroundColor = [UIColor clearColor];
            UIImageView *btn = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 22, 20)];
            [btn setImage:[UIImage imageNamed:@"sliderMenuIcon"]];
            [bv addTarget:self.navigationController.parentViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
            [btn setBackgroundColor:[UIColor clearColor]];
            [bv addSubview:btn];

            UIBarButtonItem *tempB = [[UIBarButtonItem alloc] initWithCustomView:bv];
            self.navigationItem.leftBarButtonItem = tempB;
            
            
        }
        
        if (![self.navigationItem rightBarButtonItem])
        {

        }
    }


}
ON_WILL_DISAPPEAR(signal)
{

}


@end
